<template>
  <div class="app-container">
    <div class="header">
      <el-form :inline="true" :model="queryParams" ref="ruleFormRef">
        <el-form-item label="姓名" prop="hzName">
          <el-input prefix="1" v-model="queryParams.hzName" placeholder="请输入姓名" />
        </el-form-item>
        <el-form-item label="身份证号" prop="idCardNumber">
          <el-input v-model="queryParams.idCardNumber" placeholder="请输入要搜索的身份证号">
          </el-input>
        </el-form-item>
        <el-form-item label="手机号码" prop="phonenumber">
          <el-input v-model="queryParams.phonenumber" placeholder="请输入要搜索的手机号"></el-input>
        </el-form-item>
        <el-form-item label="完成状态" prop="finishStatus">
          <el-select
            v-model="queryParams.finishStatus"
            placeholder="完成状态"
            clearable
            @keyup.enter.native="getUserListPage"
          >
            <el-option
              v-for="dict in dict.type.pea_finish_status"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="评分情况" prop="ratingStatus">
          <el-select
            v-model="queryParams.ratingStatus"
            placeholder="评分情况"
            clearable
            @keyup.enter.native="getUserListPage"
          >
            <el-option
              v-for="dict in dict.type.pea_rating_status"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="行政区域" prop="adminRegionList">
          <el-cascader
            v-model="queryParams.adminRegionList"
            :options="areaOptions"
            :style="{ width: '100%' }"
            placeholder="行政区域"
            :props="regionParams"
            clearable
          >
            <template #default="{ node, data }">
              <span>{{ data.label }}</span>
              <span v-if="!node.isLeaf"> ({{ data.children.length }}) </span>
            </template>
          </el-cascader>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="getPageList" icon="Search">查询</el-button>
          <el-button icon="Refresh" @click="reset(ruleFormRef)">重置</el-button>
        </el-form-item>
      </el-form>
    </div>

    <div class="footer">
      <div class="util">
        <el-button
          type="info"
          icon="Download"
          @click="handleExport"
        >
          导出
        </el-button>
      </div>
      <div class="table-inner">
        <el-table v-loading="loading" :data="tableData" style="width: 100%" border>
          <el-table-column label="ID" prop="hzId" width="100" align="center"></el-table-column>
          <el-table-column label="姓名" prop="hzName" width="100" align="center"></el-table-column>
          <el-table-column
            label="手机号码"
            prop="hzPhoneNumber"
            width="120"
            align="center"
          ></el-table-column>
          <el-table-column
            label="身份证号码"
            prop="hzIdCardNumber"
            width="180"
            align="center"
          ></el-table-column>
          <el-table-column label="性别" prop="hzSex" width="75" align="center">
            <template #default="scope">
              <DictTag :value="scope.row.hzSex" :options="dict.type.pea_sex"></DictTag>
            </template>
          </el-table-column>
          <el-table-column label="年龄" prop="hzAge" width="75" align="center"></el-table-column>
          <el-table-column
            label="家庭住址"
            prop="familyAddress"
            align="center"
            :show-overflow-tooltip="true"
          ></el-table-column>
          <el-table-column label="完成情况" prop="finishStatus" width="85" align="center">
            <template #default="scope">
              <DictTag
                :value="scope.row.finishStatus"
                :options="dict.type.pea_finish_status"
              ></DictTag>
            </template>
          </el-table-column>
          <el-table-column label="采集员" prop="caijiName" width="100" align="center">
          </el-table-column>
          <el-table-column label="采集员电话" prop="caijiPhonenumber" width="115" align="center">
          </el-table-column>
          <el-table-column
            label="评分情况"
            prop="ratingStatus"
            width="105"
            align="center"
            :show-overflow-tooltip="true"
          >
            <template #default="scope">
              <DictTag
                :value="scope.row.ratingStatus"
                :options="dict.type.pea_rating_status"
              ></DictTag>
            </template>
          </el-table-column>
          <el-table-column
            label="创建时间"
            prop="createTime"
            align="center"
            width="180px"
            :show-overflow-tooltip="true"
          ></el-table-column>
          <el-table-column
            label="更新时间"
            prop="updateTime"
            width="180px"
            align="center"
            :show-overflow-tooltip="true"
          ></el-table-column>
          <el-table-column label="操作" width="200" align="center">
            <template #default="scope">

            </template>
          </el-table-column>
        </el-table>
      </div>

      <div class="pagination">
        <!--分页器            -->
        <el-pagination
          v-show="total > 0"
          v-model:current-page="queryParams.pageNum"
          v-model:page-size="queryParams.pageSize"
          :page-sizes="[5, 10, 15, 20, 25, 30]"
          :background="true"
          layout="prev, pager, next, jumper, ->,  sizes, total"
          :total="total"
          @current-change="getList"
          @size-change="getList"
        />
      </div>
    </div>

  </div>
</template>
<script setup lang="ts">
import { getCurrentInstance, onMounted, reactive, ref } from "vue";
import GatherPeaInfoDialog from "@/views/credit/peasants/pea-message/components/gather-pea-info-Dialog.vue";
import { reqCrePeaPageUrl, reqCrePeaStartScoring } from "@/api/credit/peasants/pea-message";
import { ResponsePage } from "@/api/credit/peasants/pea-message/type";
import { FormInstance } from "element-plus";
import DictTag from "@/components/DictTags/index.vue";
import { reqAreaTreeSelect } from "@/api/system/user";
import { reqTableData } from "@/api/type";

const { proxy }: any = getCurrentInstance();
const queryParams = reactive({
  pageNum: 1,
  pageSize: 10,
  hzName: undefined, // 姓名
  idCardNumber: undefined, // 身份证号
  phonenumber: undefined, // 电话号码
  finishStatus: undefined, // 完成状况
  ratingStatus: undefined, // 评分情况
  xingZhengArea: undefined // 行政区域
});

const total = ref(0);
const loading = ref(true);
const tableData = ref();
// 信息收集对框框
const peaInfoDialogRef = ref();
const upDateDialogRef = ref();
const ruleFormRef = ref();
// 地域樹
const areaOptions = ref();
const regionParams = ref({
  label: "label", //这里可以配置你们后端返回的属性
  value: "id",
  children: "children",
  checkStrictly: true
});

// 查询按钮
const getPageList = () => {
  queryParams.pageNum = 1;
  getList();
};

// 分页查询
const getList = async () => {
  loading.value = true;
  await reqCrePeaPageUrl(queryParams).then((req: reqTableData) => {
    if (req.code == 200) {
      tableData.value = req.rows;
      total.value = req.total;
    } else {
      proxy.$modal.msgError(req.message);
    }
  });
  loading.value = false;
};

// 重置按钮
const reset = (formEl: FormInstance | undefined) => {
  // 将数据置空
  formEl.resetFields();
  Object.keys(queryParams).forEach((key) => {
    if(key === 'pageNum') queryParams[key] = 1
    else if(key === 'pageSize') queryParams[key] = 10
    else queryParams[key] = undefined;
  })
  // 再次进行查询
  getPageList();
};



// 导出
const handleExport = () => {

}


onMounted(async () => {
  // 进行分页查询
  await getPageList();
  // 获取新政区域
  // 获取地域树信息
  await reqAreaTreeSelect().then((req) => {
    areaOptions.value = req.data;
  });
});
</script>

<script lang="ts">
export default {
  dicts: ["sys_normal_disable", "pea_sex", "pea_finish_status", "pea_rating_status"]
};
</script>

<style scoped lang="scss">
@import './index';

</style>
